package com.sinog.front.controller.biz;

import com.sinog.core.domain.ZfbzXxgl;
import com.sinog.core.model.UserDTO;
import com.sinog.core.utilbean.Result;
import com.sinog.front.config.log.Log;
import com.sinog.front.feign.biz.GovernmentHelpService;
import com.sinog.front.service.user.UserFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @desc 安帮工作资源管理 - 政府救助帮扶信息管理 - 政府救助帮扶信息管理 - GovernmentHelpController
 * @author yms
 * @date 2020/2/7
 */
@RestController
public class GovernmentHelpController {

    @Resource
    private GovernmentHelpService governmentHelpService;
    @Autowired
    private UserFacade userService;

    /**
     * 安帮工作资源管理 - 政府救助帮扶信息管理 - 政府救助帮扶信息管理 - 列表
     * @param pageIndex pageIndex
     * @param pageSize pageSize
     * @param addusername addusername
     * @param bftype bftype
     * @return String
     */
    @RequestMapping("/azbj/zfjzbfgl/info/list")
    public String getHelpList(Integer pageIndex,Integer pageSize,
                              @RequestParam(required = false, defaultValue = "-1") String addusername,
                              @RequestParam(required = false, defaultValue = "-1") String bftype) {
        UserDTO userDTO = userService.getAuthentication();
        String departId = userDTO.getDepartid();
        Map<String,Object> mapkey = new HashMap<>(2);
        mapkey.put("addusername",addusername);
        mapkey.put("bftype",bftype);
        return governmentHelpService.getGovBfList(pageIndex,pageSize,mapkey,departId,userDTO.getLevel());
    }

    /**
     * 安帮工作资源管理 - 政府救助帮扶信息管理 - 政府救助帮扶信息管理 - （修改/新增）
     * @param request request
     * @param data data
     * @return Result
     */
    @Log(type = "新增", value = "保存政府救助帮扶信息（修改/新增）")
    @PostMapping("/azbj/zfjzbf/baseinfo/save")
    public Result saveBaseInfo(HttpServletRequest request,
                               @RequestParam(required = false, defaultValue = "-1") String data) {
        return governmentHelpService.saveBaseInfo(data);
    }

    /**
     * 安帮工作资源管理 - 政府救助帮扶信息管理 - 政府救助帮扶信息管理 - 删除
     * @param request request
     * @param id id
     * @return Result
     */
    @Log(type = "删除", value = "删除政府救助帮扶信息")
    @DeleteMapping("/azbj/zfjzbf/baseinfo/delete/{id}")
    public Result deleteBfInfo(HttpServletRequest request,@PathVariable String id) {
        return governmentHelpService.deleteBfInfo(id);
    }

    /**
     * 根据帮扶类目,查询出对应的帮扶项目
     * @param bfId bfId
     * @return List<ZfbzXxgl>
     */
    @GetMapping("/azbj/zfjzbfgl/info/getBfList")
    public List<ZfbzXxgl> getBfList(@RequestParam("bfId") String bfId) {
        return governmentHelpService.selectBfList(bfId);
    }

    /**
     * 根据帮扶救助id,查询出对应的救助金额
     * @param id id
     * @return String
     */
    @GetMapping("/azbj/zfjzbfgl/info/getBfInfo")
    public String getBfInfo(@RequestParam("id") String id) {
        return governmentHelpService.selectBfInfo(id);
    }
}